# _*_ coding : utf-8 _*_
# @Time : 2024-06-04 21:03
# @Author : haowen
# @File : getshars
# @Project : pyserver
import akshare as ak
import pandas as pd
def getshars():
    stock_zh_a_spot_em_df = ak.stock_zh_a_spot_em()
    # 创建中文字段名到英文字段名的映射字典
    column_mapping = {
        "代码": "code",
        "名称": "name",
        "最新价": "latest_price",
        "涨跌幅": "change_percent",
        "涨跌额": "change_amount",
        "涨速": "rise_speed",
        "5分钟涨跌": "five_min_change",
        "60日涨跌幅": "sixten_day_change_percent",
        "年初至今涨跌幅": "year_to_date_change_percent"
    }

    # 筛选出指定的列并替换字段名为英文
    columns_to_keep = ["代码","名称", "最新价", "涨跌幅", "涨跌额", "涨速", "5分钟涨跌", "60日涨跌幅", "年初至今涨跌幅"]
    df_filtered = stock_zh_a_spot_em_df[columns_to_keep].rename(columns=column_mapping)

    # 将 DataFrame 转换为对象
    data_objects = df_filtered.to_dict(orient='records')
    for idx, obj in enumerate(data_objects, start=1):
        obj["key"] = idx
    # list
    data_objects = data_objects[:500]
    print(data_objects)
    return data_objects

# getshars()